<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
               com.scalar.forecast.forecastEntry.SearchField,
               java.util.ArrayList,
               com.scalar.forecast.forecastEntry.RowData,
               com.scalar.forecast.commons.Constants,
               java.util.Enumeration,
                 com.scalar.forecast.forecastEntry.forms.ForecastEntryForm,
				 com.scalar.forecast.forecastEntry.TableColumn"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld"  prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld"  prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld"  prefix="nested"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld"  prefix="bean"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<SCRIPT language=JavaScript src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>
<SCRIPT>
         var noOfSlots = 0;
         var noOfRows = 0;

     function openEditColumnWindow()
     {
          newWindow = window.open ('searchMetaData.do?action=edit&tableName=FCENTRYSETUP','editColumnPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=auto,width=525 height=300,resizable=yes,left=300,top=130');
          newWindow.focus();
     }
     function openExportFileWindow()
     {
          newWindow = window.open ('export_to_file.html','exportToFilePopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=no,width=300 height=270,resizable=no,left=550,top=180');
          newWindow.focus();
     }
     function onSubmit ( actionName )
     {
          var form = document.forecastEntryForm;
          form.action.value = actionName;

          <%--//form.action = <%= "true".equalsIgnoreCase( isBuild ) ? "'forecastEntryBuildAction.do?action='" : "'forecastEntrySalesAction.do?action='" %> + actionName;--%>
          form.submit();
     }

      var dateElement = "";
      function openCalendar(dateValue)
      {
          dateElement = dateValue;
          newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
          newWindow.moveTo(550,180);
          newWindow.focus();
      }

      function assignDate(passedValue)
      {
          dateElement.value=passedValue;
          window.focus();
      }
     </SCRIPT>

<META content="MSHTML 6.00.2800.1458" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><!--TBODY-->
<TBODY>
<TR>


 <TD vAlign=top width=180
 background="<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif">
<!-- Side Navigation start -->
  <%@ include file="/jsp/marketing/marketing_menu.jsp" %>
<!-- end of the side navigations -->
 </TD>
 <TD bgColor=#ffffff><IMG height=9
   src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
 <TD bgColor=#ffffff><IMG height=480
   src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></TD>
 <TD vAlign=top width="100%"><IMG height=1
   src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0> <BR>
<!-- from here your body starts -->

<form>
<nested:root name="forecastEntryForm" >
<input type="hidden" name="action" value="">
      <script>
             noOfSlots=<nested:write property="showNext" />;
      </script>
   <TABLE width="100%" align=center border=0>
     <TBODY>
     <TR>
       <TD class=NArialW align=middle colSpan=5>Build Forecast View</TD></TR>
     <TR>
          <TD colSpan=5>&nbsp;</TD></TR>
      <TR><TD colspan='5' id='errorMessagesId'><chiptrack:errors styleClass='NArialL' /></TD></TR>
      <TR><TD colspan='5' id='infoMessagesId'><chiptrack:info styleClass='NArialL' /></TD></TR>
      <TR><TD colspan='5' class="NArialL"><FONT id="errorsId"  color='FF0000'></FONT></TD></TR>
      <TR><TD colSpan=5>&nbsp;</TD></TR>
     <TR>
       <TD>
         <TABLE width="100%" border=0>
           <TBODY>
           <% int tdIdxCnt = 0; %>
            <nested:iterate property="searchFieldList" indexId="idx" id="searchField">
              <nested:equal property="display" value="true">
                 <% Integer tdidx = new Integer ( (++tdIdxCnt)%2 );
                    pageContext.setAttribute( "tdidx",tdidx );%>
                 <logic:equal name="tdidx" value="1" scope="page">
                    <TR>
                      <TD width="20%"><FONT class=NArialL><nested:write property="displayName"/>:</FONT></TD>
                      <TD class=NArialL width="25%"><nested:write property="propertyValue"/></TD>
                 </logic:equal>
                 <logic:equal name="tdidx" value="0" scope="page">
                      <TD width="5%">&nbsp;</TD>
                      <TD class=NArialL width="20%"><nested:write property="displayName"/>:</TD>
                      <TD class=NArialL width="30%"><nested:write property="propertyValue"/>
                          <nested:equal property="displayName" value="Show Next">
                              &nbsp;<bean:write name="showNext" scope="request"/>
                          </nested:equal>
                     </TD>
                   </TR>
                 </logic:equal>
              </nested:equal>
            </nested:iterate>
           <TR>
             <TD bgColor=#ffffff><IMG height=9
               src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD></TR>
           <TR>
             <TD width="100%" colSpan=5><!-- sales forecast entry table starts here -->
               <TABLE width="100%" border=0>
                 <TBODY>
              <%--<TR align=middle>
                  <TD colspan=10 class=NArialL> <A href="javascript:openEditColumnWindow()">[ Edit Column Display ] </A>&nbsp;&nbsp;&nbsp;&nbsp;<A href="javascript:openExportFileWindow()">[ Export to File ]</A></TD>
              </TR>--%>

              <TR>
                  <TD height=5><IMG
                           src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"
                           width=10 height=5></TD>
              </TR>

                 <TR align=middle bgColor=#993333>

                          <TD align=middle><FONT class=NArialL
                     style="color:#ffffff;">Sales Person</FONT></TD>

           <nested:nest property="tableMetaData">
              <nested:iterate property="slotNames">
                   <%
                       ForecastEntryForm forecastEntryForm = ( ForecastEntryForm )request.getAttribute( "forecastEntryForm" );
					   int colSpan =  0;
					   if ( forecastEntryForm != null )
					   {
						   colSpan = forecastEntryForm.getTableMetaData().getNoOfTableColumns();
						   ArrayList tableColumnList = forecastEntryForm.getTableMetaData().getTableColumnList ( );
						   int tableColumnListSize = ( tableColumnList == null ) ? 0 : tableColumnList.size();
						   for ( int i = 0; i < tableColumnListSize; i++ )
						   {
							   TableColumn tableColumn = ( TableColumn ) tableColumnList.get ( i );
							   if ( "Confidence Level".equalsIgnoreCase ( tableColumn.getName() ) && tableColumn.isDisplay() )
							   {
								   colSpan = colSpan - 1;
								   break;
							   }
						   }
					   }
                   %>
                   <TD align=middle colSpan='<%=colSpan%><%--<nested:write property="tableMetaData/noOfTableColumns" />--%>' ><FONT class=NArialL
                     style="color:#ffffff;"><nested:write property="label"/></FONT></TD>
              </nested:iterate>
                 </TR>
                 <TR align=middle bgColor=#f2dbdb>
                         <TD></TD>
               <nested:iterate property="slotNames">
                  <nested:nest property="/tableMetaData">
                  <nested:iterate property="tableColumnList">
                      <nested:equal property="display" value="true">
                        <nested:notEqual property="name" value="Confidence Level">
                          <TD class=NArialL noWrap width=55 align="center"><nested:write property="displayName"/><%--Qty--%></TD>
                        </nested:notEqual>
                      </nested:equal>
                  </nested:iterate>
                  </nested:nest>
               </nested:iterate>
           </nested:nest>
                 </TR>

                <TR align="right" class='color1' <%--id='<%=rowId.toString()%>'--%> <%--style="DISPLAY: <%=styleDisplay%>"--%>><!-- level-4 row  ( root )-->
                    <TD class=NArialL align="right">Default Build&nbsp;</TD>


                     <nested:nest property="/buildRowData">
                         <nested:iterate property="slotDataList" indexId="slotDataListIdx" id="slotData">
                              <nested:nest property="/tableMetaData">
                                  <nested:iterate property="tableColumnList">
                                   <nested:equal property="display" value="true">

                                      <nested:equal property="name" value="Qty">
                                                <TD class=NArialL>
                                                    <bean:write name="slotData" property="qty"/>
                                                </TD>
                                      </nested:equal>
                                      <nested:equal property="name" value="Price">
                                                <TD class=NArialL>
                                                    <bean:write name="slotData" property="price"/>
                                                </TD>
                                      </nested:equal>
                                      <%--<nested:equal property="name" value="Confidence Level">
                                          <TD class=NArialL>

                                          </TD>
                                      </nested:equal>--%>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERLIST1%>">
                                          <TD class=NArialL>
                                          </TD>
                                      </nested:equal>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERDATE1%>">
                                          <TD class=NArialL>
                                          </TD>
                                      </nested:equal>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERTXT1%>">
                                          <TD class=NArialL>
                                          </TD>
                                      </nested:equal>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERTXT2%>">
                                          <TD class=NArialL>
                                          </TD>
                                      </nested:equal>
                                   </nested:equal>
                                  </nested:iterate>
                              </nested:nest>
                         </nested:iterate>
                     </nested:nest>
               </TR>

                 <% String rowIds[] = null; int rootCnt = 0, rowCnt = 0; %>
          <nested:iterate property="tableDataList" indexId="tableDataListIdx" id="rowData" >
              <%
                  rowCnt++;
                  int maxLevel = ( ( RowData )rowData ).getMaxLevelOrder();
                  int currentLevel = ( ( RowData ) rowData ).getLevelOrder();

                  //if ( tableDataListIdx.intValue() == 0 )
                  if ( maxLevel == currentLevel )
                  {
                      rootCnt++;
                      rowIds = new String[ maxLevel + 1 ];
                      for ( int i=0; i < maxLevel+1; i++ )
                      {
                          rowIds[i] = new String("");
                      }
                  }

                  StringBuffer rowId = new StringBuffer ( "" );
                  if ( "".equals( rowIds[ currentLevel ] ) )
                  {
                      if ( currentLevel == maxLevel )
                      {
                          rowId.append ( "r" );
                          rowId.append ( rootCnt );
                          rowId.append ( "l" );
                          rowId.append ( maxLevel );
                      }
                      else if ( currentLevel < maxLevel )
                      {
                          rowId.append ( rowIds[ currentLevel + 1 ] );
                          rowId.append ( "c1" );
                      }

                      rowIds[currentLevel] = rowId.toString();
                  }
                  else
                  {
                      rowId.append ( rowIds[ currentLevel ] );
                      int childCnt = Integer.parseInt ( rowId.substring( rowId.lastIndexOf( "c" )+1 ) );
                      childCnt = childCnt + 1;
                      rowId.replace( rowId.lastIndexOf ( "c" )+1,rowId.length(),Integer.toString( childCnt ) );
                      rowIds[ currentLevel ] = rowId.toString();
                  }
                  int colorIdx = ( maxLevel - currentLevel ) + 1;
                  int noOfSpaces = maxLevel - currentLevel;
                  String styleDisplay = ( maxLevel == currentLevel ) ? "block" : "none";
              %>
                <TR align="right" class='color<%=( colorIdx > 4 ) ? 4 : colorIdx%>' id='<%=rowId.toString()%>' <%--style="DISPLAY: <%=styleDisplay%>"--%>><!-- level-4 row  ( root )-->
                  <TD>
                     <TABLE align="left">
                        <TBODY >
                            <TR>
                                <TD class=NArialL><nested:write property="salesPersonName"/></TD>
                            </TR>
                        </TBODY>
                      </TABLE>
                  </TD>
                         <% String rowDataProp = "",slotDataProp=""; %>
                         <nested:iterate property="slotDataList" indexId="slotDataListIdx" id="slotData">
                              <nested:nest property="/tableMetaData">
                                  <nested:iterate property="tableColumnList">
                                   <nested:equal property="display" value="true">
                                       <%  rowDataProp = "/tableDataList[" + tableDataListIdx.intValue()+ "]";
                                           slotDataProp = "slotDataList[" + slotDataListIdx.intValue() + "]";
                                        %>
                                      <nested:equal property="name" value="Qty">
                                        <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%= slotDataProp%>">
                                          <TD class=NArialL>
                                                  <nested:hidden property="rowId"/>

                                                  <nested:write property="qty"/>

                                          </TD>
                                         </nested:nest>
                                        </nested:nest>

                                      </nested:equal>
                                      <nested:equal property="name" value="Price">
                                          <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%=slotDataProp%>">
                                          <TD class=NArialL>
                                                      <nested:write property="price"/>

                                          </TD>
                                              </nested:nest>
                                          </nested:nest>
                                      </nested:equal>
                                      <%--<nested:equal property="name" value="Confidence Level">
                                          <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%=slotDataProp%>">
                                          <TD class=NArialL>
                                                      <logic:equal value="1" name="currentLevel" scope="page" >
                                                          <nested:write property="confidenceLevel"/>
                                                      </logic:equal>
                                          </TD>
                                          </nested:nest>
                                              </nested:nest>
                                      </nested:equal>--%>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERLIST1%>">
                                          <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%=slotDataProp%>">
                                          <TD class=NArialL>

                                                      <nested:write property="userList1"/>

                                          </TD>
                                           </nested:nest>
                                              </nested:nest>
                                      </nested:equal>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERDATE1%>">
                                          <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%=slotDataProp%>">
                                          <TD class=NArialL>

                                                      <nested:write property="userDate1"/>
                                          </TD>
                                          </nested:nest>
                                              </nested:nest>
                                      </nested:equal>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERTXT1%>">
                                          <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%=slotDataProp%>">
                                          <TD class=NArialL>

                                                      <nested:write property="userTxt1"/>
                                          </TD>
                                          </nested:nest>
                                              </nested:nest>
                                      </nested:equal>
                                      <nested:equal property="name" value="<%=Constants.COLUMN_USERTXT2%>">
                                          <nested:nest property="<%=rowDataProp%>">
                                              <nested:nest property="<%=slotDataProp%>">
                                          <TD class=NArialL>

                                                      <nested:write property="userTxt2"/>
                                          </TD>
                                          </nested:nest>
                                              </nested:nest>
                                      </nested:equal>
                                   </nested:equal>
                                  </nested:iterate>
                              </nested:nest>
                         </nested:iterate>

               </TR>
               </nested:iterate>
               <script>noOfRows=<%=rowCnt%>;</script>
               </TBODY></TABLE><!-- sales forecast entry table ends here -->


      </TD></TR></TBODY></TABLE></TD></TR>
     <TR>
       <TD><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"
width=10></TD></TR>

    <TR>
        <TD align=middle colspan=5><A href="forecastEntrySearchAction.do?action=searchBuild"><IMG
             onmouseover="window.status='Click to go back to Build Forecast Search';return true"
             title="Click to go back to Build Forecast Search"
             onmouseout="window.status='';return true"
             src="<%=chipTracContext%>/jsp/includes/images/back.gif" border=0  ></A></TD>
    </TR>

    </TBODY></TABLE>
<!-- Body Ends Here -->
      </TD>
  </TR>
 </nested:root>
 </form>
<%--</html:form>--%>
  </TBODY>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>